/**
 * 
 */
package com.gr.staffpm.pages.schedule;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gr.staffpm.pages.schedule.model.Event;


/**
 * @author Graham Rhodes 31 Mar 2011 14:44:34
 */
public class WeekViewEventPanel extends Panel {

    private static final long serialVersionUID = 1L;
    private final RepeatingView events = new RepeatingView("events");
    private final List<WeekViewEvent> eventsList = new ArrayList<WeekViewEvent>();
    private final Logger log = LoggerFactory.getLogger(getClass());

    public WeekViewEventPanel(String id) {
        super(id);
        add(events);
    }

    public void addEvent(String id, Event event) {
        WeekViewEvent newWeekEvent = new WeekViewEvent(id, event);
        int amountOfEvents = 1;
        for (WeekViewEvent weekEvent : eventsList) {
            if (newWeekEvent.isContainedWithin(weekEvent)) {
                amountOfEvents++;
                newWeekEvent.setWidth(100 / amountOfEvents);
                weekEvent.setWidth(100 / amountOfEvents);
                newWeekEvent.setLeft(100 / amountOfEvents);
            }
        }
        eventsList.add(newWeekEvent);
        events.add(newWeekEvent);
    }

    public void removeAllEvents() {
        events.removeAll();
        eventsList.removeAll(eventsList);
    }

}
